package Filter;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class UserListFilter implements Filter {

	public void destroy() {
		
	}
	

	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)req;
		HttpServletResponse response = (HttpServletResponse)resp;
		HttpSession session = request.getSession();
		PrintWriter out = response.getWriter();
		String url = "error.jsp";
		String role = "";
		role =  (String) session.getAttribute("role");
		if(role.equals("1")){
			chain.doFilter(req,resp);
			return;
		}
		else{
			System.out.println("无权查阅！");
			out.print("<script type='text/javascript'>  alert('无权查阅！'); location.href='jump?status=index';</script>");
		}
	}

	public void init(FilterConfig fConfig) throws ServletException {
		
	}

}
